/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ImageFrame.java
 *
 * Created on 27 sept. 2009, 18:48:10
 */

package jvgallery;

import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;

/**
 *
 * @author guillaume
 */
public class ImageFrame extends javax.swing.JFrame {

    /**
     * Constructor -- with Image path
     * @param imagepath
     */
    public ImageFrame(String imagepath)
    {
        initComponents();

        // Load image
        ImageContainer imgc = new ImageContainer(imagepath);

        // Add image to container
        this.imagePanel.add(imgc);
        this.validate();

        // Resizes window to show the full image
        this.setSize(imgc.getWidth(), imgc.getHeight());

        // Display this frame in the center of the screen viewport
        this.setLocationRelativeTo(null);

        // Window title = image (file) name
        this.setTitle(imgc.getName());

        // Show
        this.setVisible(Boolean.TRUE);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        imagePanel = new javax.swing.JPanel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setName("Form"); // NOI18N

        imagePanel.setName("imagePanel"); // NOI18N
        imagePanel.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                imagePanelMouseClicked(evt);
            }
        });
        imagePanel.setLayout(new java.awt.BorderLayout());
        getContentPane().add(imagePanel, java.awt.BorderLayout.CENTER);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void imagePanelMouseClicked(java.awt.event.MouseEvent evt)//GEN-FIRST:event_imagePanelMouseClicked
    {//GEN-HEADEREND:event_imagePanelMouseClicked
        // Close this window and destroy it (free memory)
        this.dispose();
    }//GEN-LAST:event_imagePanelMouseClicked

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel imagePanel;
    // End of variables declaration//GEN-END:variables

}
